<template>
  <div>
    <el-table :data="tableDate" style="width: 100%">
      <el-table-column prop="iname" label="产品名称" />
      <el-table-column prop="status" label="状态" v-slot="scope">
        <el-tag v-if="scope.row.status === 0" type="success">持有</el-tag>
        <el-tag v-if="scope.row.status === 1" type="danger">售出</el-tag>
      </el-table-column>
      <el-table-column prop="yieldMonth" label="月利率" />
      <el-table-column prop="yieldYear" label="年利率" />
      <el-table-column prop="startMoney" label="单股价格" />
      <el-table-column prop="remark" label="购买股份" />
      <el-table-column v-slot="scope" label="产品总值">
        <span>{{ scope.row.startMoney * scope.row.remark }}</span>
      </el-table-column>
      <el-table-column v-slot="scope">
        <el-input-number v-if="scope.row.status==0" v-model="scope.row.riskLevel" :min="1" :max="scope.row.remark" />
      </el-table-column>
      <el-table-column v-slot="scope">
        <el-button v-if="scope.row.status==0" @click="sell(scope.row)">售卖</el-button>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { myList, sellfinancal } from '@/api/finanicl'

const tableDate = ref([])

function sell(va) {
  console.log(va)
  sellfinancal(va.id, va.remark, va.riskLevel, va.startMoney).then(resp => {
    if (resp.data === true) {
      alert('售卖成功')
      finaAll()
    }
  })
}
function finaAll() {
  myList().then(resp => {
    tableDate.value = resp.data
    console.log(resp.data)
  })
}
finaAll()
</script>

<style scoped></style>
